<?php require_once 'source.php';?>
<?php require_once 'config.php';?>
<?php require_once 'dao/dao_db.php';?>
<?php require_once 'dao/dao_qa.php';?>
<?php require_once 'dao/dao_sys_manage.php';?>
<?php 
	$result=is_bbs_on();
	$row=mysql_fetch_array($result);
	if($row['BBSSWITCH']==OFF){
		mysql_close();
		header('Location: error.php?errcode=2');
		exit;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo SYSTITLE?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div class="wrapper">
<?php require_once 'header.php';?>
<div id="layout">
	<div id="leftlay"><?php require_once 'leftnav.php';?></div>
	<div id="rightlay">
		<div class="columntitle"><?php echo BBSMANAGE?></div>
		<div class="columncontent">
		<?php 
			if($_SESSION['level']==TEACHER||$_SESSION['level']==STUDENT){
		?>
			<div><a href="create_question.php"><?php echo CREATEDISCUSSION?></a></div>
		<?php }?>
			<?php 	
				if($_SESSION['userid']!=''&&$_SESSION['level']!==ADMINISTRATOR){
					$result=get_group_member($_SESSION['userid']);
					$str_sql='';
					while(($row=mysql_fetch_array($result))!=false){
						$str_sql.=$row['USERID'].',';
					}
					$str_sql = substr($str_sql,0,-1);
					$author=$result['USERGROUP'];
					$result=get_questions_list($author,$str_sql);
				if(mysql_num_rows($result)!=0){
			?>
				<table class="temptable">
				<tr>
					<th><?php echo REPORTTITLE?></th>					
					<th><?php echo COMMENTSNUM?></th>
					<th><?php echo PUBLICDATE?></th>
				</tr>
				<?php 
					while(($row=mysql_fetch_array($result))!=false){
						$title=$row['TITLE'];
				?>
					<tr>
						<td width="300"><a href="discussion.php?qid=<?php echo $row['Id']?>" target="_blank"><?php echo $title?></a></td>							
						<td><?php echo get_comments_num($row['Id'])?></td>
						<td><?php echo $row['DATETIME']?></td>
					</tr>
				<?php }?>
				</table>
			<?php 
				}else{echo NOREPORT;}	
			}elseif($_SESSION['userid']!=''&&$_SESSION['level']==ADMINISTRATOR){
				$result=get_questions_list_a();
				if(mysql_num_rows($result)!=0){
			?>
				<table class="temptable">
				<tr>
					<th><?php echo REPORTTITLE?></th>					
					<th><?php echo COMMENTSNUM?></th>
					<th><?php echo PUBLICDATE?></th>
					<th><?php echo IPADDRESS?></th>
					<th><?php echo ACTION?></th>
				</tr>
				<?php 
					while(($row=mysql_fetch_array($result))!=false){
						$title=$row['TITLE'];
				?>
					<tr>
						<td width="300"><a href="discussion.php?qid=<?php echo $row['Id']?>" target="_blank"><?php echo $title?></a></td>							
						<td><?php echo get_comments_num($row['Id'])?></td>
						<td><?php echo $row['DATETIME']?></td>
						<td><?php echo $row['IPADDRESS']?></td>
						<td><a href="service/service_save_questions.php?id=<?php echo $row['Id']?>"><?php echo DEL?></a></td>
					</tr>
				<?php 
					}
				}else{
					echo NOREPORT;
				}
				?>
				</table>
			<?php 	
			}
			mysql_close();
			?>
		</div>
	</div>
</div>
</div>
</body>
</html>
